/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 script_build_building.cpp

	$Header: /heroes4/script_build_building.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "script_build_building.h"

#include "sized_int_types.h"
#include "streambuf_operators.h"
#include "town.h"
#include "town_building.h"

// --------------------------------------------------------------------------
// t_script_build_building members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_build_building::read(
	std::streambuf &	stream,
	int					version )
{
	if ( !t_abstract_script_action::read( stream, version ) )
		return false;
	
	m_building = get< t_town_building >( stream );

	return true;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_build_building::read_from_map(
	std::streambuf &	stream,
	int					format_version )
{
	m_building = t_town_building( get< t_uint8 >( stream ) );
	return m_building >= 0 && m_building < k_town_building_count;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_build_building::write( std::streambuf & stream ) const
{
	if ( !t_abstract_script_action::write( stream ) )
		return false;
	
	put< t_town_building >( stream, m_building );
	
	return true;
}

void t_script_build_building::execute(t_script_context_hero const& context) const
{
	assert(false);
}

void t_script_build_building::execute(t_script_context_town const& context) const
{
	t_town* town = context.object ? context.object->get_town() : context.town;
	if (town == NULL) {
		assert(false);
		return;
	}
	town->create_building(get_building());
}

void t_script_build_building::execute(t_script_context_object const& context) const
{
	assert(false);
}

void t_script_build_building::execute(t_script_context_army const& context) const
{
	assert(false);
}

void t_script_build_building::execute(t_script_context_global const& context) const
{
	assert(false);
}
